#include "reconnaissance.h"

using namespace std;

// projette l'image d'un visage dans l'espace d'un visage
// l'neregistre dans un fichier sous forme de matrice colonne
void projectImg(string inputPath)
{
    CvMat *visages, *eigenvectors, *eigenT, *projections, *projection;
    visages=getPictures(inputPath);

    if(Matrix::loadFromFile("eigenvectors.mat", eigenvectors))
    {
        eigenT = cvCreateMat(eigenvectors->width, eigenvectors->height, CV_32F);
        cvTranspose(eigenvectors, eigenT);

        projections = cvCreateMat(eigenT->height, visages->width, CV_32F);
        cvMatMul(eigenT, visages, projections);

        int height = projections->height;
        int width = projections->width;

        for(int i=0 ; i<width ; i++)
        {
            projection = cvCreateMat(height, 1, CV_32F);

            for(int j=0 ; j<height ; j++)
                cvmSet(projection, j, 0, cvmGet(projections, j, i));

            string iStr;
            stringstream ss;
            ss << i;
            ss >> iStr;

            Matrix::saveIntoFile(inputPath+"/"+iStr+".p", projection);
        }
    }
    else
    {
        cout << "Echec chargement eigenvectors" << endl;
    }
}
